package br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;

import br.ufpe.cin.msc.jrsj2.recommender.persistence.dao.ClientDAO;
import br.ufpe.cin.msc.jrsj2.recommender.persistence.entity.Client;

public class JPAClientDAO implements ClientDAO {

	private EntityManager emf;

	public JPAClientDAO(EntityManager emf) {
		this.emf = emf;
	}

	@Override
	public void create(Client client) {
		try {
			emf.getTransaction().begin();
			emf.persist(client);
			emf.getTransaction().commit();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	@Override
	public Client findById(String id) {
		return emf.find(Client.class, id);
	}

	@Override
	public void remove(String id) {
		Client client = this.findById(id);

		if (client == null)
			return;
		emf.remove(client);
	}

	@Override
	public List<Client> loadAll() {
		return null;
	}

}
